# buff_manager.gd
class_name BuffManager
extends Node

var active_buffs: Array = []  # 当前激活的Buff实例

# 添加Buff
func add_buff(buff_res: BuffResource, target: Node):
	# 检查是否可叠加或刷新时间
	var existing = find_existing_buff(buff_res)
	if existing:
		existing.reset_duration()
	else:
		var buff_instance = Buff.new(buff_res, target)
		active_buffs.append(buff_instance)

# 每帧更新Buff,如果持续时间结束则从表中移除
func _process(delta: float):
	for buff in active_buffs.duplicate():
		if buff.process(delta):
			buff.remove()
			active_buffs.erase(buff)

# 查找同类Buff
func find_existing_buff(buff_res: BuffResource):
	for buff in active_buffs:
		if buff.resource == buff_res:
			return buff
	return null
